﻿using System;
using System.Windows;
using System.Windows.Media;
using NUnit.Framework;

namespace OpenPowerPointTest.Helpers
{
    /// <summary>
    /// Tests the unit conversion
    /// </summary>
    /// <remarks> <seealso cref="UnitConversion"/></remarks>
    [TestFixture]
    [Category("Unit: Converter")]
    class UnitConversion
    {
        /// <summary>
        /// Does PtToEmu work?
        /// </summary>
        /// <remarks><seealso cref="OpenPowerPoint.Conversion.UnitConversion.PtToEmu"/></remarks>
        [Test]
        public void PtToEmu()
        {
            Assert.AreEqual(1530350, OpenPowerPoint.Conversion.UnitConversion.PtToEmu(120.5));
        }

        /// <summary>
        /// Does EmuToPt work?
        /// </summary>
        /// <remarks><seealso cref="OpenPowerPoint.Conversion.UnitConversion.EmuToPt"/></remarks>
        [Test]
        public void EmuToPt()
        {
            Assert.AreEqual(120.5, OpenPowerPoint.Conversion.UnitConversion.EmuToPt(1530350));
        }

        [Test]
        public void UnderlineToWPF()
        {
            Assert.AreEqual(TextDecorations.Underline, OpenPowerPoint.Conversion.DrawingConverters.UnderlineToWpf(DocumentFormat.OpenXml.Drawing.TextUnderlineValues.Single));
        }

        [Test]
        public void EmuDegree()
        {
            Assert.AreEqual(90, OpenPowerPoint.Conversion.UnitConversion.EmuToDegree(5400000));
            Assert.AreEqual(5400000, OpenPowerPoint.Conversion.UnitConversion.DegreeToEmu(90));
        }

        [Test]
        public void CmEmu()
        {
            Assert.AreEqual(5, OpenPowerPoint.Conversion.UnitConversion.PtToCm(OpenPowerPoint.Conversion.UnitConversion.EmuToPt(1800000)));
            Assert.AreEqual(1800000, OpenPowerPoint.Conversion.UnitConversion.PtToEmu(OpenPowerPoint.Conversion.UnitConversion.CmToPt(5)));
        }

        [Datapoints]
        Color[] colors = new Color[] { Colors.Azure, Colors.Beige, Colors.Aquamarine, Colors.WhiteSmoke };
        [Datapoints]
        byte[] values = new byte[] { 0xFF, 0x00, 0xCC, 0xAB, 0x16, 0x0F, 0xD5, 124, 57, 174, 209, 65, 4 };
        [Datapoints]
        Tuple<int, int>[] cinqalSystem = new Tuple<int, int>[] { new Tuple<int, int>(20, 10), new Tuple<int, int>(22, 12), new Tuple<int, int>(132, 42),
            new Tuple<int, int>(10, 5), new Tuple<int, int>(111, 31), new Tuple<int, int>(104, 29), new Tuple<int, int>(44, 24), new Tuple<int, int>(1142, 172)};
        [Datapoints]
        string[] strings = new string[] { "test", "test2", "famnfasf", "WAFIJASF", "00\n\t\r\b" };

        [Theory]
        public void ColorStorage(Color color, byte value)
        {
            color = OpenPowerPoint.Conversion.UnitConversion.ExToColor(color, value);
            Assume.That(value == OpenPowerPoint.Conversion.UnitConversion.ColorToEx(color));
        }

        [Theory]
        public void FontStorage(string text)
        {
            FontFamily font = new FontFamily("Comic Sans MS");

            font = OpenPowerPoint.Conversion.UnitConversion.ExToFont(font, text);
            Assume.That(text == OpenPowerPoint.Conversion.UnitConversion.FontToEx(font));
        }

        [Theory]
        public void CinqalConvert(Tuple<int, int> number)
        {
            Assume.That(number.Item1 == OpenPowerPoint.Conversion.UnitConversion.DecToCinq(number.Item2));
        }


        [Theory]
        public void CinqalConvertBack(Tuple<int, int> number)
        {
            Assume.That(number.Item2 == OpenPowerPoint.Conversion.UnitConversion.CinqToDec(number.Item1));
        }
    }
}
